/*  This file is part of Real Time Digital Audio Processing library.
 *  Copyright (C) 2008 - Emilio Monti - emilmont@gmail.com
 *
 *  Real Time Digital Audio Processing library is free software: you can
 *  redistribute it and/or modify it under the terms of the GNU General
 *  Public License as published by the Free Software Foundation, either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  Real Time Digital Audio Processing library is distributed in the hope
 *  that it will be useful, but WITHOUT ANY WARRANTY; without even the
 *  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *  See the GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Real Time Audio Processing library.
 *  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef VAD_H_
#define VAD_H_

#include "Module.h"
#include "RMS.h"

class VAD : Module {
    public:
        VAD(unsigned long framesPerBuffer, unsigned int sampleRate, float activity_threshold, float hangover_time_s, RMS* rms);
        void processSignal(float* signal, unsigned long length);
        virtual ~VAD() {};

    protected:
        bool active;
        RMS* rms;
        float activity_threshold;
        int hangover_buffers;
        int hangCount;
        unsigned int word_index;
};

#define PARROT_MEMORY  132300
class Parrot : public VAD {
    public:
        Parrot(float delay_s, unsigned long framesPerBuffer, unsigned int sampleRate, float activity_threshold, float hangover_time_s, RMS* rms);
        void processSignal(float* signal, unsigned long length);

    private:
        float memory[PARROT_MEMORY];
        unsigned int memory_index;

        unsigned int delay_samples;
        unsigned int delay_index;
};

#endif /*VAD_H_*/
